const { render } = require('../../router/News.js')
const Model=require('../index.js')
module.exports=class User extends Model{
    static getUserList(){
        return new Promise((resolve,reject)=>{
            const sql='select * from user'
            this.query(sql).then(result=>{
                resolve(result)
            }).catch(err=>{
                reject(err)
            })
        })
    }
    static addUser(age,birthday,type,name,icon){
        return new Promise((resolve,reject)=>{
            let create_time=new Date()
            const sql='insert into user (name,age,type,birthday,icon,create_time) values (?,?,?,?,?,?)'
            this.query(sql,[name,age,type,birthday,icon,create_time]).then(result=>{
                resolve(result.insertId)
            }).catch(err=>{
                reject(err)
            })
        })
    }
    static checkUsername(username){
        return new Promise((resolve,reject)=>{
            const sql='select username from user where username=?'
            this.query(sql,[username]).then(result=>{
                resolve(result)
            }).catch(err=>{
                reject(err)
            })
        })
    }
    static login(username,password){
        return new Promise((resolve,reject)=>{
            const sql='select username,password from user where username=? and password=?'
            this.query(sql,[username,password]).then(result=>{
                resolve(result)
            }).catch(err=>{
                reject(err)
            })
        })
    }
}